﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace WMM.Tapioca.Formula.Aspects
{
    /// <summary>
    /// An entity identifier rule is an aspect rule that addresses the entity identifier aspect
    /// and that is expressed by the <formula:entityIdentifier> element. 
    /// </summary>
    public class EntityIdentifierAspect : Aspect
    {
        private XElement element;

        internal XElement Element
        {
            get { return element; }
            set { element = value; }
        }        

        private string scheme;

        /// <returns> The entity identifier scheme. </returns>
        public string Scheme
        {
            get { return scheme; }
            set { scheme = value; }
        }

        private string valueScheme;

        /// <returns> The entity identifier value. </returns>
        public string ValueScheme
        {
            get { return valueScheme; }
            set { valueScheme = value; }
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        public EntityIdentifierAspect(XElement entityIdentifierAspect)
        {
            this.Element = entityIdentifierAspect;

            XElement aspect = entityIdentifierAspect.Parent;

            if (aspect.Attribute("source") != null)
            {
                this.Source = aspect.Attribute("source").Value;
            }

            if (entityIdentifierAspect.Attribute("source") != null)
            {
                this.Source = entityIdentifierAspect.Attribute("source").Value;
            }

            XAttribute scheme = entityIdentifierAspect.Attribute("scheme");

            if (scheme != null)
            {
                this.Scheme = scheme.Value;
            }

            XAttribute value = entityIdentifierAspect.Attribute("value");

            if (value != null)
            {
                this.ValueScheme = value.Value;
            }
        }
    }
}
